added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / ATLShellExtIconOverlayHandler / FileIconOverlayExt.cpp
blob22a7e1ccb13352f8c8504b4b184fd81505151821
1 /****************************** Module Header ******************************\
2 * Module Name: FileIconOverlayExt.cpp
3 * Project: ATLShellExtIconOverlayHandler
4 * Copyright (c) Microsoft Corporation.
5 *
6 * Icon overlays are small images placed at the lower-left corner of the icon
7 * that represents a Shell object. They are normally added to an object's icon
8 * to provide some extra information. For instance, a commonly used icon
9 * overlay is the small arrow that indicates that the icon represents a link,
10 * rather than the actual file or folder. In addition to the standard icon
11 * overlays that are provided by the system, you can request custom icon
12 * overlays for specified Shell objects by implementing and registering an
13 * icon overlay handler.
15 * FileIconOverlayExt in ATLShellExtIconOverlayHandler demonstrates a shell
16 * icon overlay handler for files with "Sample" in the file paths. After
17 * installing the icon overlay handler, any file with "Sample" in its file
18 * path, e.g. "D:\Sample.txt", shows an icon overlay in Windows Explorer.
20 * This source is subject to the Microsoft Public License.
21 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
22 * All other rights reserved.
24 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
25 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
27 \***************************************************************************/
29 #pragma region Includes
30 #include "stdafx.h"
31 #include "FileIconOverlayExt.h"
32 #pragma endregion
35 /////////////////////////////////////////////////////////////////////////////
36 // CFileIconOverlayExt IShellIconOverlayIdentifier methods.
37 //
40 // FUNCTION: CFileIconOverlayExt::GetOverlayInfo(LPWSTR, int, int*, DWORD*)
42 // PURPOSE: Provides the location of the icon overlay's bitmap. This method
43 // is first called during initialization, it returns the fully
44 // qualified path of the file containing the icon overlay image,
45 // and its zero-based index within the file. The icon can be
46 // contained in any of the standard file types, including .exe,
47 // .dll, and .ico. After initialization is complete, the Shell
48 // calls GetOverlayInfo when it needs to display the handler's
49 // icon overlay. The method should return the same file name and
50 // index that it did during initialization. Although the Shell
51 // uses the image that is cached in the system image list rather
52 // than loading the image from the file, an icon overlay is still
53 // identified by its file name and index.
55 IFACEMETHODIMP CFileIconOverlayExt::GetOverlayInfo(
56 LPWSTR pwszIconFile, int cchMax, int* pIndex, DWORD* pdwFlags)
58 // Get the module's full path
59 GetModuleFileNameW(_AtlBaseModule.GetModuleInstance(), pwszIconFile,
60 cchMax);
62 // Use the first icon in the resource
63 *pIndex = 0;
65 *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
67 return S_OK;
72 // FUNCTION: CFileIconOverlayExt::GetPriority(int*)
74 // PURPOSE: Specifies the priority of an icon overlay. This method is
75 // called only during initialization. It assigns a priority value
76 // to the handler's icon overlay. The value can range from zero to
77 // 100, where 100 is the lowest priority. The purpose of this
78 // priority value is to help the Shell resolve the conflict that
79 // arises when multiple icon overlays are specified for a single
80 // object. The Shell first uses an internal set of rules to
81 // determine the highest priority icon overlay. If these rules do
82 // not resolve the conflict, the values assigned to the icon
83 // overlays by GetPriority determine priority. The priority value
84 // set by GetPriority is not a reliable way to resolve conflicts
85 // between unrelated icon overlay handlers. There is no way for
86 // your handler to determine what priority values other handlers
87 // are using. Normally, you should set the value to zero. However,
88 // the priority value is useful when you have implemented two or
89 // more icon overlay handlers that can request icon overlay icons
90 // for the same object. By setting the priority values
91 // appropriately, you can specify which of the requested icon
92 // overlays will be displayed.
94 IFACEMETHODIMP CFileIconOverlayExt::GetPriority(int* pPriority)
96 // Request the highest priority
97 *pPriority = 0;
99 return S_OK;
104 // FUNCTION: CFileIconOverlayExt::IsMemberOf(LPCWSTR, DWORD)
106 // PURPOSE: Specifies whether an icon overlay should be added to a Shell
107 // object's icon or not. The Shell calls this method to determine
108 // whether it should display a handler's icon overlay for a
109 // particular object. It specifies the object by passing its name
110 // to the method. If a handler wants to have its icon overlay
111 // displayed, IsMemberOf returns S_OK. If not, it returns S_FALSE.
112 // Icon overlay handlers are normally intended to work with a
113 // particular group of files. A typical example is a file class,
114 // identified by a specific file name extension. An icon overlay
115 // handler can request an icon overlay for all members of the file
116 // class. Some handlers request an icon overlay only if a member
117 // of the file class is in a particular state. However, icon
118 // overlay handlers are free to request their icon overlay for any
119 // object that they want.
121 IFACEMETHODIMP CFileIconOverlayExt::IsMemberOf(LPCWSTR pwszPath,
122 DWORD dwAttrib)
124 // If the file name contains "Sample", add the overlay
125 if (wcsstr(pwszPath, L"Sample") != 0)
126 return S_OK;
127 else
128 return S_FALSE;